package com.yuanren.em.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yuanren.em.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    /*
        以下为引入mybatis-plus之前的操作

    @Select("select * from sys_user")
    List<User> findFrontGoods();
    @Insert("insert into sys_user(username,password,nickname,email,phone,address) " +
        "values (#{username},#{password},#{nickname},#{email},#{phone},#{address})")
    int insert(User user);

    int update(User user);

    @Delete("delete from sys_user where id = #{id}")
    int deleteById(@Param("id") int id);

    List<User> selectPage(int index,int pageSize,String username,String nickname);

    int searchTotal(String username, String nickname);

     */

    /**
     * 获取所有用户ID
     */
    @Select("SELECT id FROM sys_user WHERE is_delete = 0")
    List<Long> selectAllUserIds();
    
    /**
     * 根据等级获取用户ID列表
     */
    @Select("<script>" +
            "SELECT u.id FROM sys_user u " +
            "LEFT JOIN t_user_member um ON u.id = um.user_id " +
            "WHERE u.is_delete = 0 " +
            "<if test='levelIds != null and levelIds.size() > 0'>" +
            "AND um.current_level_id IN " +
            "<foreach collection='levelIds' item='levelId' open='(' separator=',' close=')'>" +
            "#{levelId}" +
            "</foreach>" +
            "</if>" +
            "</script>")
    List<Long> selectUserIdsByLevels(@Param("levelIds") List<Long> levelIds);
}
